<?php
/*
*网站设置
*/
$mod='blank';
include '../Core/Common.php';
$act=$_GET['act'];
/*
*头部核心判断
*/
?>
<?php
/*
*在线上传更新包
*/
if($act=='update'){//源文件名：update.php
	$title='更新包上传';
	include './Head.php';
	//功能流程开始
	echo '
	<div class="block">
			<div class="panel-heading">
				<h3 class="panel-title">程序更新包(请打包更新包，系统会自动解压)</h3>
			</div>
			<div class="panel-body">';
	if($_POST['s']==1){
		$extension=explode('.',$_FILES['file']['name']);
		if(($length=count($extension))>1){
			$ext=strtolower($extension[$length - 1]);
		}
		if($ext=='zip'){//判断是否是zip类 防止恶意上传
			echo "上传成功，正在解压中";
			copy($_FILES['file']['tmp_name'], ROOT.PACKAGE_DIR.'/update/update.zip');
			$zip = new ZipArchive;
			if($zip->open(ROOT.PACKAGE_DIR.'/update/update.zip') && $zip->extractTo(ROOT.PACKAGE_DIR.'/update/')){
				echo '<p>更新包解压成功</p>';
				$zip->close(ROOT.PACKAGE_DIR.'/update/update.zip');
				unlink(ROOT.PACKAGE_DIR.'/update/update.zip');
				exit ('<p>更新包已经自动删除</p>');
			}else{
				exit('<p>更新包解压失败</p>');
			}
		}
		else{
			echo "<font color=red>请打包好更新包再上传，系统会自动解压！</font>";
		}
	}
	if($_GET['mod']=='clean'){
		if(delFile(ROOT.PACKAGE_DIR.'/update')==true){
			exit('<p>原旧数据已经删除</p>');
		}else{
			exit('<p>原旧数据未能删除，请检查目录是否有权限</p>');
		}
	}
	//核心流程结束
	echo ' 	<form action="Up.php?act=update" method="POST" enctype="multipart/form-data">
				<label for="file"></label>
				<input type="file" name="file" id="file"/>
				<input type="hidden" name="s" value="1"/><br>
				<input type="submit" class="btn btn-primary btn-block" value="确认上传"/>
				<a href="Up.php?act=update&mod=clean" class="btn btn-info btn-block">清空原数据</a>
				</form>';
	echo '</div> <div class="panel-footer">
          <span class="glyphicon glyphicon-info-sign"></span> 
		  <font color=red>注意:上传之前请先清空原安装包数据<br></font>';
}
?>

<?php
/*
*在线上传安装包
*/
if($act=='release'){//源文件名：release.php
	$title='安装包上传';
	include './Head.php';
	//功能流程开始
	echo '<div class="block">
			<div class="panel-heading">
				<h3 class="panel-title">程序安装包(请打包安装包，系统会自动解压)</h3>
			</div>
			<div class="panel-body">';
	if($_POST['s']==1){
		$extension=explode('.',$_FILES['file']['name']);
		if(($length=count($extension))>1){
			$ext=strtolower($extension[$length - 1]);
		}
		if($ext=='zip'){//判断是否是zip类 防止恶意上传
			echo "上传成功，正在解压中";
			copy($_FILES['file']['tmp_name'], ROOT.PACKAGE_DIR.'/release/release.zip');
			$zip = new ZipArchive;
			if($zip->open(ROOT.PACKAGE_DIR.'/release/release.zip') && $zip->extractTo(ROOT.PACKAGE_DIR.'/release/')){
				echo '<p>安装包解压成功</p>';
				$zip->close(ROOT.PACKAGE_DIR.'/release/release.zip');
				unlink(ROOT.PACKAGE_DIR.'/release/release.zip');
				exit ('<p>安装包已经自动删除</p>');
			}else{
				exit('<p>安装包解压失败</p>');
			}
		}
		else{
			echo "<font color=red>请打包好安装包再上传，系统会自动解压！</font>";
		}
	}
	if($_GET['mod']=='clean'){
		if(delFile(ROOT.PACKAGE_DIR.'/release')==true){
			exit('<p>原旧数据已经删除</p>');
		}else{
			exit('<p>原旧数据未能删除，请检查目录是否有权限</p>');
		}
	}
	//核心流程结束
	echo ' 	<form action="Up.php?act=release" method="POST" enctype="multipart/form-data">
				<label for="file"></label>
				<input type="file" name="file" id="file"/>
				<input type="hidden" name="s" value="1"/><br>
				<input type="submit" class="btn btn-primary btn-block" value="确认上传"/>
				<a href="Up.php?act=release&mod=clean" class="btn btn-info btn-block">清空原数据</a>
			</form>';
	echo '</div> <div class="panel-footer">
          <span class="glyphicon glyphicon-info-sign"></span> 
		  <font color=red>注意:上传之前请先清空原安装包数据<br></font>';
}
function delFile( $dirName )
{
if ( $handle = opendir( "$dirName" ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != "." && $item != ".." ) {
if ( is_dir( "$dirName/$item" ) ) {
delFile( "$dirName/$item" );
} else {
if( unlink( "$dirName/$item" ) )echo "成功删除文件： $dirName/$item \n";
}
}
}
closedir( $handle );
if( rmdir( $dirName ) )echo "成功删除目录： $dirName \n";
}
}
?>